package com.hundsun.yr.universal.p2p.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.library.widget.HSEditText;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;

/**
 * Created by xx on 2017/7/19.
 */
public class InvestTermActivity extends BaseActivity implements View.OnClickListener{
    private HSEditText hset_min_invest_term;
    private HSEditText hset_max_invest_term;
    private HSButton btn_sure;
    private int SETTINGINVESTTERM = 4;
    private String minterm;
    private String maxterm;


    @Override
    protected boolean isApplyKitKatTranslucency() {
        return true;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_invest_term;
    }

    @Override
    protected void initViewsAndEvents() {
        findView();
        toolbar_title.setText(getString(R.string.investment_duration));
        btn_sure.setOnClickListener(this);

        hset_min_invest_term.setText(minterm);
        hset_max_invest_term.setText(maxterm);
    }

    public void findView(){
        hset_min_invest_term = findView(R.id.hset_min_invest_term);
        hset_max_invest_term = findView(R.id.hset_max_invest_term);
        btn_sure = findView(R.id.btn_sure);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        minterm = extras.getString("minterm");
        maxterm = extras.getString("maxterm");
    }

    @Override
    protected void onEveComming(EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    public void onClick(View view) {
        if (!NetUtils.isNetworkConnected(mContext)){
            showToast(R.string.common_no_network);
            return;
        }
        switch (view.getId()){
            case R.id.btn_sure:
                String minterm = hset_min_invest_term.getText().toString();
                String maxterm = hset_max_invest_term.getText().toString();

                if (minterm.isEmpty()){
                    showToast("请输入最小投资期限");
                    return;
                }

                if (maxterm.isEmpty()){
                    showToast("请输入最大投资期限");
                    return;
                }

                if (MathUtils.compare(minterm,"10") < 0){
                    showToast("最小投资期限不能小于10天");
                    return;
                }

                if (MathUtils.compare(maxterm,"360") > 0){
                    showToast("最大投资期限不能超过360天");
                    return;
                }

                if (MathUtils.compare(minterm,maxterm) > 0){
                    showToast("您输入的最小投资期限，大于最大投资期限");
                    return;
                }

                Intent intent = getIntent();
                intent.putExtra("minterm",minterm);
                intent.putExtra("maxterm",maxterm);
                setResult(SETTINGINVESTTERM,intent);
                finish();
                break;
        }
    }
}
